package com.shanghaiyimu.yimiyangche.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;

import android.view.ViewGroup;


import java.util.List;

/**
 * Created by Administrator on 2017/7/3.
 */

public class MyViewPageAdapter extends PagerAdapter {
    private List<View> data;

    public MyViewPageAdapter(List<View> data){
        this.data = data;
    }
    @Override
    public int getCount() {
        return data != null?data.size():0;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View ret = null;
        ret = data.get(position);
        container.addView(ret);
        return ret;
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (object instanceof View){
            View view = (View) object;
            container.removeView(view);
        }
    }
}
